import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { ExamineButton, OpenTwoRouter, DelDataButton } from '../Common/options'

export const WeeklyReports = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}Added`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            // <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
        ],
        columns: [
            { ...commonTableList.SearchSort, selectType: 'WeeklyReports' },
            // {
            //     ...commonTableList.parentUuid,
            //     fieldProps: {
            //         fieldNames: { label: 'tableName', value: 'uuid' },
            //         options: parentUuid,
            //     },
            // },
            commonTableList.uuid,
            {
                dataIndex: 'date',
                title: '日期',
                valueType: 'render',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                render: (_, { monday, friday }) => (
                    <div>
                        {' '}
                        {monday.split(' ')[0]} 至 {friday.split(' ')[0]}
                    </div>
                ),
            },
            {
                dataIndex: 'departmentName',
                title: '部门',
                valueType: 'input',
                width: 200,
                hideInAdded: true,
            },
            {
                dataIndex: 'status',
                title: '状态',
                valueType: 'select',
                valueEnum: {
                    0: { text: '未提交', status: 'Error' },
                    1: { text: '已提交', status: 'Success' },
                    2: { text: '迟交', status: 'Warning' },
                },
                width: 200,
                hideInAdded: true,
            },
            {
                dataIndex: 'createTime',
                title: '提交日期',
                valueType: 'input',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
            },
            {
                dataIndex: 'createUserName',
                title: '提交人员',
                valueType: 'input',
                width: 200,
                hideInAdded: true,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 160,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, friday, status } = record
                    return [
                        status === 0 && (
                            <ExamineButton
                                key="one"
                                title="提交周报"
                                data={{
                                    actionRef,
                                    OptionsEvent,
                                    url: 'posWeeklyReports',
                                    smallTitle: '提交周报',
                                }}
                                options={[
                                    { title: '提交', type: 'primary', emit: { data: { uuid, OperationDate: friday } } },
                                    { title: '取消', type: 'link', emit: 'off' },
                                ]}
                            />
                        ),
                        status !== 0 && (
                            <OpenTwoRouter
                                key="TwoOne"
                                title="附件管理"
                                modal="TableList"
                                OptionsEvent={OptionsEvent}
                                other={{
                                    page: 'AttachmentDetails',
                                    actionRef,
                                    Permission,
                                    oneData: record,
                                    header: data.columns,
                                }}
                            />
                        ),
                        status !== 0 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }

    return data
}
